<template>
  <div>
    <el-table border :data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))">
      <el-table-column prop="id" label="序号" width="90" align="center">
      </el-table-column>
      <el-table-column prop="name" label="名称" width="250" align="center">
      </el-table-column>
      <el-table-column prop="price" label="单价" width="200" align="center">
      </el-table-column>
      <el-table-column prop="Specifications" label="规格" width="200" align="center">
      </el-table-column>
      <el-table-column prop="number" label="数量" align="center">
      </el-table-column>
      <el-table-column prop="exa" label="审核状态" align="center">
      </el-table-column>
      <el-table-column width="300" align="center">
        <template slot="header" slot-scope="scope">
          <el-input
            v-model="search"
            placeholder="输入关键字搜索"/>
        </template>
        <div slot-scope="scope">
          <el-button size="mini" icon="el-icon-plus" @click="push(scope.row, scope.$index)">增加药品数量</el-button>
          <el-button size="mini" icon="el-icon-delete-solid" @click="del(scope.row, scope.$index)">删除</el-button>
        </div>
      </el-table-column>
    </el-table>
    <div>
      <el-button type="primary" size="mini" icon="el-icon-plus" @click="add">添加药品</el-button>
    </div>
    <div>
      <el-dialog title="药品信息" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item label="序号" :label-width="form.formLabelWidth">
            <el-input v-model="form.id" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="名称" :label-width="form.formLabelWidth">
            <el-input v-model="form.name" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="单价" :label-width="form.formLabelWidth">
            <el-input v-model="form.price" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="规格" :label-width="form.formLabelWidth">
            <el-input v-model="form.Specifications" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="数量" :label-width="form.formLabelWidth">
            <el-input v-model="form.number" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addOk">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      tableData: [
        {
          id: 1,
          name: '荷兰小犬二联',
          number: 100,
          price: '40',
          Specifications: '10支/每盒',
          exa: '审核通过'
        },
        {
          id: 2,
          name: '二联血清',
          number: 10,
          price: '60',
          Specifications: '10支/每盒',
          exa: '审核通过'
        },
        {
          id: 3,
          name: '国产六联',
          number: 100,
          price: '10',
          Specifications: '10支/每盒',
          exa: '审核通过'
        },
        {
          id: 4,
          name: '免疫球蛋白',
          number: 100,
          price: '65',
          Specifications: '10支/每盒',
          exa: '审核通过'
        },
        {
          id: 5,
          name: '荷兰五联苗',
          number: 100,
          price: '40',
          Specifications: '10支/每盒',
          exa: '审核通过'
        },
        {
          id: 6,
          name: '抗犬瘟1号',
          number: 100,
          price: '10',
          Specifications: '12支/每盒',
          exa: '审核通过'
        },
        {
          id: 7,
          name: '宠物洗眼液',
          number: 100,
          price: '10',
          Specifications: '50ml/每瓶',
          exa: '审核通过'
        },
        {
          id: 8,
          name: '维迪康（口服）',
          number: 100,
          price: '15',
          Specifications: '12瓶/每盒',
          exa: '审核通过'
        }
      ],
      id: '',
      name: '',
      price: '',
      Specifications: '',
      number: '',
      form: {
        id: '',
        name: '',
        price: '',
        Specifications: '',
        number: '',
        formLabelWidth: '120px'
      },
      dialogFormVisible: false,
      search: ''
    }
  },
  methods: {
    push (row, index) {
      console.log(row.number)
      row.number += 1
      this.tableData[index].number = row.number
    },
    del (row, index) {
      console.log(row)
      this.tableData.splice(index, 1)
    },
    add () {
      this.dialogFormVisible = true
    },
    addOk () {
      var lit = {
        id: this.form.id,
        name: this.form.name,
        price: this.form.price,
        Specifications: this.form.Specifications,
        number: this.form.number
      }
      this.tableData.push(lit)
      this.dialogFormVisible = false
    }
  }
}
</script>
<style scoped>

</style>
